﻿//-----------------------------------------------------------------------
// <copyright file="StatusWindow.xaml.cs" company="Luboš Bretschnieder">
// Copyright (c) 2008 Luboš Bretschnieder, Licensed under the Apache License, Version 2.0.
// </copyright>
//-----------------------------------------------------------------------
namespace GraphAlgorithms
{
    using System.Collections.Generic;
    using System.Windows.Controls;
    using Graphs.UI;

    /// <summary>
    /// Interaction logic for StatusWindow.xaml
    /// </summary>
    public partial class StatusWindow
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="StatusWindow"/> class.
        /// </summary>
        /// <param name="statusBars">The status bars.</param>
        public StatusWindow(IEnumerable<IStatusBar> statusBars)
        {
            InitializeComponent();

            this.StatusBars = statusBars;
            this.UpdateStatus();
        }

        /// <summary>
        /// Gets or sets the status bars.
        /// </summary>
        /// <value>The status bars.</value>
        public IEnumerable<IStatusBar> StatusBars { get; set; }

        /// <summary>
        /// Updates the status.
        /// </summary>
        public void UpdateStatus()
        {
            StackPanelStatus.Children.Clear();

            if (this.StatusBars != null)
            {
                foreach (IStatusBar statusBar in this.StatusBars)
                {
                    this.AddStatusBar(statusBar);
                }
            }
        }

        /// <summary>
        /// Adds the status bar.
        /// </summary>
        /// <param name="statusBar">The status bar.</param>
        private void AddStatusBar(IStatusBar statusBar)
        {
            Label lblLabel = new Label { Content = (statusBar.Label + ": ") };
            Label lblStatus = new Label { Content = statusBar.ToStatusString() };
            StackPanel sp = new StackPanel { Orientation = Orientation.Horizontal };

            sp.Children.Add(lblLabel);
            sp.Children.Add(lblStatus);

            StackPanelStatus.Children.Add(sp);
        }
    }
}
